package com.多线程07.demo21;

public class SiSuoTest {

    public static void main(String[] args) {
//        准备两把锁
        final Object objA = new Object();
        final Object objB = new Object();

        new Thread(
                new Runnable() {
                    @Override
                    public void run() {
                        while (true){
                            synchronized (objA){
                                synchronized (objB){
                                    System.out.println(Thread.currentThread().getName()+"小A同学正在跑步");
                                }
                            }
                        }
                    }
                }
    ,"线程1").start();

        new Thread(
                new Runnable() {
                    @Override
                    public void run() {
                        while (true){
                            synchronized (objB){
                                synchronized (objA){
                                    System.out.println(Thread.currentThread().getName()+"小B同学正在跑步");
                                }
                            }
                        }
                    }
                }
                ,"线程2").start();

//        new Thread(()->{
//            while (true){
//                synchronized (objB){
//                    synchronized (objA){
//                        System.out.println(Thread.currentThread().getName()+"小康同学正在跑步");
//                    }
//                }
//            }
//        },"线程2").start();
    }

}
